package com.cyy.test_t_4_;
/**
 * 剑指Offer 面试题41_1
 * 和为S的两个数字；
 * 输入一个递增排序的数组和一个数字s,在数组中查找两个数，
 * 是的它们的和正好是s。如果有多对数字的和对于s，输出任意一对即可
 */
public class t_41_1 {

	public static void main(String[] args) {
      
		int a[] = {1,2,4,6,9,11,15};
		FindNumbersWithSum(a,15);
	}
	
	static void FindNumbersWithSum(int data[],int s){
		int len = data.length;
		if(data == null || len < 1){
			return;
		}
		
		int ahead = len - 1;
		int behind = 0;
		
		while(ahead > behind){
			long curSum = data[ahead] + data[behind];
			
			if(curSum == s){
				System.out.println(data[behind] + ","+data[ahead]);
				break;
			}else if(curSum > s){
				ahead --;
			} else{
				behind ++;
			}
		}
		
	}

}
